package com.usian.wemedia.controller;

import com.baomidou.mybatisplus.core.toolkit.StringUtils;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.usian.api.wemedia.WmUserControllerApi;
import com.usian.model.common.dtos.ResponseResult;
import com.usian.model.media.pojos.WmUser;
import com.usian.wemedia.service.WmUserService;
import com.usian.wemedia.service.impl.WmUserServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.ws.rs.Path;

@RestController
@RequestMapping("/api/v1/user")
public class WmUserController implements WmUserControllerApi {

    @Autowired
    private WmUserServiceImpl service;

    @PostMapping("/save")
    @Override
    public ResponseResult save(@RequestBody WmUser wmUser){
        if (wmUser == null) return service.errorParam;
        service.save(wmUser);
        return service.success;
    }

    @Override
    @GetMapping("/api/v1/author/findByUserId/{id}")
    public WmUser findByName(@PathVariable String name) {
        return service.getOne(Wrappers.<WmUser>lambdaQuery().eq(StringUtils.isEmpty(name),WmUser::getName,name));
    }

}
